/**
 * \file scalar_storage.hpp
 * 
 * \section COPYRIGHT
 *
 * Basis: A 3D Mathematics Library
 *
 * ---------------------------------------------------------------------
 *
 * Copyright (c) 2010, Don Olmstead
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *  1. Redistributions of source code must retain the above copyright notice,
 *     this list of conditions and the following disclaimer.
 *
 *  2. Redistributions in binary form must reproduce the above copyright notice,
 *     this list of conditions and the following disclaimer in the documentation
 *     and/or other materials provided with the distribution.
 *
 *  3. Neither the name of organization nor the names of its contributors may be
 *     used to endorse or promote products derived from this software without
 *     specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef BASIS_DETAIL_SCALAR_STORAGE_HPP_INCLUDED
#define BASIS_DETAIL_SCALAR_STORAGE_HPP_INCLUDED

namespace basis { namespace detail
{
	/**
	 * Stores a scalar in array form.
	 *
	 * Used in an expression template to allow scalar values to
	 * mimic an array.
	 *
	 * \tparam T A scalar type.
	 *
	 * \author Don Olmstead
	 * \version 0.1
	 */
	template <typename T>
	class scalar_storage
	{
		public:

			/// Value of type T
			typedef T value_type;
			/// Reference to a type T
			typedef T& reference;
			/// Const reference to a type T
			typedef const T& const_reference;
			/// Unsigned integral type
			typedef std::size_t size_type;

			/**
			 * Initializes an instance of scalar_storage.
			 *
			 * \param scalar The value of the scalar.
			 */
			scalar_storage(const_reference scalar)
				: _scalar(scalar)
			{ }

			/**
			 * Array operator for the scalar_storage class.
			 *
			 * \param i The index to lookup.
			 * \returns The scalar.
			 */
			inline value_type operator[] (size_type i) const
			{
				return _scalar;
			}

			/**
			 * Retrieves the size of the scalar_storage.
			 *
			 * The scalar_storage has no size.
			 *
			 * \returns 0.
			 */
			static inline size_type size()
			{
				return 0;
			}

		private:

			/// The scalar
			const_reference _scalar;

	} ; // end class scalar_storage

} } // end namespace basis::detail

#endif // end BASIS_DETAIL_STORAGE_HPP_INCLUDED
